#pragma once

#include "BehavioredClassifier.h"

#include "Behavior.h"
#include "InterfaceRealization.h"

namespace uml {

void BehavioredClassifier::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    PartialElement::fromJson(json, errorList);
    classifierBehavior_ = JsonSerializable::create<Behavior>(json.value("classifierBehavior"), errorList);

    JsonSerializable::fromJsonArray(interfaceRealizations_, "interfaceRealizations", json, errorList);
    JsonSerializable::fromJsonArray(ownedBehaviors_, "ownedBehaviors", json, errorList);
}

void BehavioredClassifier::toJson(QJsonObject& json) {
    PartialElement::toJson(json);
    if (classifierBehavior_) {
        QJsonObject classifierBehavior_json;
        classifierBehavior_->toJson(classifierBehavior_json);
        json.insert("classifierBehavior", classifierBehavior_json);
    }
    JsonSerializable::toJsonArray(interfaceRealizations_, "interfaceRealizations", json);
    JsonSerializable::toJsonArray(ownedBehaviors_, "ownedBehaviors", json);
}

/// <summary>
/// classifierBehavior getter
/// A Behavior that specifies the behavior of the BehavioredClassifier itself.
/// </summary>
shared_ptr<Behavior> BehavioredClassifier::classifierBehavior() const {
    return classifierBehavior_;
}

/// <summary>
/// classifierBehavior setter
/// A Behavior that specifies the behavior of the BehavioredClassifier itself.
/// </summary>
void BehavioredClassifier::setClassifierBehavior(shared_ptr<Behavior> value) {
    classifierBehavior_ = value;
}

/// <summary>
/// interfaceRealizations getter
/// The set of InterfaceRealizations owned by the BehavioredClassifier. Interface
/// realizations reference the Interfaces of which the BehavioredClassifier is an
/// implementation.
/// </summary>
vector<shared_ptr<InterfaceRealization>>& BehavioredClassifier::interfaceRealizations() {
    return interfaceRealizations_;
}

/// <summary>
/// ownedBehaviors getter
/// Behaviors owned by a BehavioredClassifier.
/// </summary>
vector<shared_ptr<Behavior>>& BehavioredClassifier::ownedBehaviors() {
    return ownedBehaviors_;
}

} // namespace uml
